
require("config")
require("framework.init")
require("framework.shortcodes")
require("framework.cc.init")

local GameScene  = class("GameScene", function()
    return display.newScene("GameScene")
end)


local TAG_MYSCENE      = 10

function GameScene:ctor()

  local item = ui.newImageMenuItem({image='CloseNormal.png',imageSelected='CloseSelected.png',listener=onClicked})
  local menu = ui.newMenu({item}):addTo(self)
  menu:pos(display.width-40,display.height-40)
  menu:setZOrder(4)
  local touch = display.newLayer():addTo(self)
  touch:setTouchEnabled(true)
  touch:addNodeEventListener(cc.NODE_TOUCH_EVENT, onTouch)

  CCArmatureDataManager:sharedArmatureDataManager():addArmatureFileInfo('NewAnimation02.csb') --('NewAnimation02.ExportJson')
  local armature = CCArmature:create("NewAnimation02")
  armature:setTag(10)
  self:addChild(armature)
  armature:pos(display.cx,display.cy+200)
  armature:getAnimation():play('Animation2')
  

  local bone = armature:getBone('b1_bo')
  if not bone then
    CCLuaLog('... not have bone ...')
  else
    CCLuaLog('... have bone ...')
  end
  --armature:removeBone(bone,true)

  dis = bone:getDisplayManager()
  if not dis then
    CCLuaLog('... not have dis ...')
  else
    CCLuaLog('... have dis ...')
  end
  local s=dis:getContentSize()
  printf('s w=%d,h=%d', s.width,s.height)
  
  local sp = display.newSprite('CloseNormal.png')--:addTo(nNode)
  dis:addDisplay(sp,1)
  dis:changeDisplayWithIndex(1,true)          -- true保持替换的Node，false，下个循环会换回原来的

  local bone3 = armature:getBone('b3_bo')
  local skin = CCSkin:create('CloseNormal.png')   --通过CCSkin创建皮肤
  bone3:addDisplay(skin, 1)                       --再加入骨骼中
  bone3:changeDisplayWithIndex(1,true)            --切换皮肤


end

local index = 0
local frameIndex = 30
function onClicked(tag)
  CCLuaLog('... onClicked ...')
  local armature = display.getRunningScene():getChildByTag(10)
  --[[
  armature:getAnimation():gotoAndPause(frameIndex)          --停止动画于frameIndex帧
  frameIndex = frameIndex+30
  if(frameIndex > 120) then frameIndex = 0 end
  ]]
  dis:changeDisplayWithIndex(index,true) 
  if index == 0 then index = 1 else index = 0 end

  return false
end


function onTouch(event)
  if event.name == 'began' then
    CCLuaLog('... onTouch ...')
  elseif event.name == 'moved' then


  end

 
  return true
 
end


function GameScene:onEnter()
	CCLuaLog('GameScene:onEnter')																				--启用定时器监听
end


function GameScene:enterScene(sceneName, args, transitionType, time, more)
	 print('GameScene:enterScene..................')
end

function GameScene:onEnterFrame(dt)
  
end

game = {}

function game.startup()
    CCFileUtils:sharedFileUtils():addSearchPath("res/")
    print('startup..................')
    game.enterMainScene()
end

function game.exit()
    CCDirector:sharedDirector():endToLua()
    print('exit..........')
end

function game.enterMainScene()
	print('GameScene.new',type(GameScene.new))
    display.replaceScene(GameScene.new(), "fade", 0.6, display.COLOR_WHITE)
end
return game